<?php
#### SERVER LOAD ###############################################################
// Function to retrieve server load
function server_load()
{
	if (ini_get('safe_mode')) {
		return 'Unknown (PHP in Safe Mode)';
	// Don't forget to be kind to Mac's!
	} else if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
		return 'Unknown (Windows Server)';
	} else {
		if (file_exists('/proc/loadavg')) {
			$file = @fopen('/proc/loadavg', 'r');
			if (!$file) return 0;
			$load = fread($file, 14);
			fclose($file);
			
		} else {
			$load = @exec('uptime');
			if (!$load) return 0;
			$load_array = split('load averages?: ', $load);
			$load = $load_array[1];
		}
		return trim($load);
	}
}

#### SERVER UPTIME #############################################################
// Function to retrieve server uptime
function server_uptime()
{
	if (ini_get('safe_mode')) {
		return 'Unknown (PHP in Safe Mode)';
	} else 
	// Don't forget to be kind to Mac's!
	if (stristr(PHP_OS, 'WIN')  && !stristr(PHP_OS, 'darwin')) {
		return 'Unknown (Because you are running Windows Server)';
	} else {
		if (file_exists('/proc/uptime')) {
			$file = @fopen('/proc/uptime', 'r');
			if (!$file) return 0;
			$uptime = fread($file, 25);
			fclose($file);
			$uptime = split(' ', $uptime);
			$uptime = seconds_to_string($uptime[1]);
		} else {
			$uptime = @exec('uptime');
			if (!$uptime) return 0;
			$uptime_array = explode(',', $uptime);
			$uptime_array = split('up:?', $uptime_array[0]);
			$uptime = $uptime_array[1];
		}
		return trim($uptime);
	}
}
?>